package framework.util.queryFilter.vo;

import java.util.List;

/**
 * @author 吴宇亮 on 2019/2/21 0021 22:45
 */
public class Insert<BoType> extends AbstactSql {

    private Integer lid; //间接接收lid, 到时候回传给bo
    private String tableName;
    private BoType bo;

    //用于mapper文件拼接sql
    private List<_Field> fieldList;

    public Insert(BoType bo){
        this.bo = bo;
    }

    /**
     * 根据persistType获取要插入数据库的
     * @param clazz
     */
    @Override
    public void generatorSql(Class clazz) throws NoSuchFieldException {
        //生成要insert的values, 要这种格式：(#{item.lid,jdbcType=INTEGER}, #{item.cname,jdbcType=VARCHAR})
        StringBuilder sb = new StringBuilder(fieldList.size() * 30);
        sb.append("(");
        for(int i = 0, j = fieldList.size(); i < j; i++){
            _Field field = fieldList.get(i);
            if(i != j - 1){
                sb.append("#{item.bo."+field.getFieldName()+",jdbcType="+field.getFieldType()+"}, ");
            }else{
                sb.append("#{item.bo."+field.getFieldName()+",jdbcType="+field.getFieldType()+"}");
            }
        }
        sb.append(")");
        this.generatorSql = sb.toString();
    }

    public Integer getLid() {
        return lid;
    }

    public void setLid(Integer lid) {
        this.lid = lid;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public BoType getBo() {
        return bo;
    }

    public void setBo(BoType bo) {
        this.bo = bo;
    }

    public List<_Field> getFieldList() {
        return fieldList;
    }

    public void setFieldList(List<_Field> fieldList) {
        this.fieldList = fieldList;
    }

}
